<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="java.util.List" %>
<%@ page import="yxnote.*" %>
<%@ page import="category.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Category</title>
</head>
<body>
<div>
Current User is <%= UserFactory.getUser().getNickname() %>
</div>

<div>

<form id="del" action="?" method="post">
</form>

<script type="text/javascript">
function del(id) {
	if (!confirm("Are you sure?"))
		return false;
	var frm = document.getElementById('del');
	frm.action = "/category/delete?id=" + id;
	frm.submit();
	return false;
}
</script>
<%
List<Category> categorys = Utils.find();
if (categorys.isEmpty()) {
%>
没有数据
<% } else { %>
<table>
<%for(Category c:categorys) {%>
    <tr>
	    <td><%= c.getName() %></td>
	    <td> 
		    <a href="javascript:void(0)" onclick="del(<%= c.getKey().getId() %>)">Del</a>
		    <a href="/category/update.jsp?id=<%= c.getKey().getId() %>">Update</a>
	    </td>
    </tr>
<%}%>
</table>    

<% }%>
</div>
    <form action="/category/create" method="post">
      <div><label>Category Name:</label><input name="name" /></div>
      <div><input type="submit" value="Add Category" /></div>
    </form>
</body>
</html>
